package com.jk.vehicle.mini.controller.base;

import com.jk.vehicle.mini.entity.MileageRecord;
import com.jk.vehicle.mini.entity.User;
import com.jk.vehicle.mini.service.CorpService;
import com.jk.vehicle.mini.service.MileageRecordService;
import com.jk.vehicle.core.controller.BaseController;
import com.jk.vehicle.core.entity.ResponseEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jk.vehicle.mini.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * This is Description for MileageRecordController
 *
 * @author Administrator
 * @date 2021/02/08
 */
@Api(value = "里程单表数据", tags = "里程单表数据")
@RestController
@RequestMapping("/mileage/record")
public class MileageRecordController extends BaseController {

	/**
	 * MileageRecordService服务
	 */
    @Resource
    private MileageRecordService mileageRecordService;

    @Resource
    private CorpService corpService;

    @Resource
    private UserService userService;

	/**
	 * 新增mileageRecord
	 * @param mileageRecord
	 * @return
	 */
	@ApiOperation("新增里程数据(首页开关锁之后)")
    @PostMapping
    public ResponseEntity add(@RequestBody MileageRecord mileageRecord) {
        if (mileageRecord.getCorpId().longValue() == 0 || mileageRecord.getCorpId() == null) {
            return failResult("厂家id不能为空！");
        }
        if (mileageRecord.getCorpId() == -1) {
            return failResult("厂家id不能等于-1！");
        }
        User user = userService.findById(mileageRecord.getUserId(), null);
        if (user == null) {
            return failResult("该用户不存在！");
        }
        String dsName = corpService.selectDsNameById(mileageRecord.getCorpId());
        mileageRecordService.save(mileageRecord, dsName);
        return successResult(mileageRecord);
    }
}
